<template>
	<view class="body">
		<view class="head">
			<view class="head_left"  @click="back"><image src="/static/img/fanhui.png"></image></view>
			<view class="head_center hei_38_bold">积分明细</view>
			<view class="head_right hei_30"></view>
		</view>
		<view class="content">
			<view class="app_content">
				<view class="zijin_tab hui_30">
					<text>说明</text>
					<text>数量</text>
					
				</view>
				<view class="zijin_list">
					
					<view class="zijin_item hui_30" v-for="(item,index) in list" >
						<view class="zijin_item_tab">
							<text class="hei_30">{{item.reason}}</text>
							<text class="hong_34">{{item.points}}</text>
							
							
						</view>
						<view>
							
							<text class="qian_26">{{item.created_at}}</text>
						</view>
					</view>
					
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			img_url: uni.getStorageSync('img_url'),
			page: 1,
			list: [],
			limit:10,
			is_all: false,
			state:'',
			type:''
		};
	},

	onShow() {},
	onLoad(option) {
		if(option.type){
			this.type=option.type
		}
		this.get_user()
		
	},
	//下拉刷新
	onPullDownRefresh: function() {
		this.list = [];
		this.page = 0;
		this.get_list();
	},
	methods: {
		//上拉加载
		onReachBottom() {
			console.log('上拉加载');
			if (this.is_all) {
				uni.showToast({
					title: '没有更多内容了',
					duration: 2000,
					icon: 'none'
				});
				uni.stopPullDownRefresh();
			} else {
				this.page++;
				this.get_list();
			}
		},
		back() {
			uni.navigateBack();
		},
		get_user() {
			this.$http
				.get({
					url: '/api/getUserInfo',
					data:{
						none_load:true,
					}
				})
				.then(res => {
					if (res.code == 200) {
						if (res.user) {
							this.is_login=true
							this.user = res.user;
							this.get_list();
							
						} else {
							this.is_login=false
						}
					}
				});
		},
		get_list(){
			this.$http
				.get({
					url: '/api/getPointRecordsByUserIdAndPage',
					data: {
						page: this.page,
						limit:this.limit,
						userId:this.user.id
					}
				})
				.then(res => {
					if (res.code == 200) {

						this.list=this.list.concat(res.records)
						
						
						if(res.records.length < this.limit){
						    this.is_all=true
						}else{
							this.is_all=false
						}
					}
				});
			
		}
	},
	filters: {
		timeStamp: function(value) {
			if (value == null) {
				return 'null';
			}
			var i = (value + '').length;
			while (i++ < 13) value = value + '0';
			value = Number(value);
			var date = new Date(value);
			//date.setTime(value);
			var month = date.getMonth() + 1;
			var hours = date.getHours();
			if (hours < 10) hours = '0' + hours;
			var minutes = date.getMinutes();
			if (minutes < 10) minutes = '0' + minutes;
			var time = date.getFullYear() + '-' + month + '-' + date.getDate() + ' ' + hours + ':' + minutes;
			return time;
		}
	}
};
</script>

<style>
.head {
	border-bottom: 1px solid #eeeeee;
}
.content {

}
.zijin_list{
	padding: 0 20rpx;
}
.zijin_item {
	padding: 30rpx 0 30rpx;
	border-bottom: 1px solid #EEEEEE;
	
}

.zijin_item view {
	display: flex;
	align-items: center;
	justify-content: space-between;
	
}
.zijin_tab{
	display: flex;
	align-items: center;
	height: 88rpx;
	background-color: #f5f5f5;
	padding: 0 20rpx;
	justify-content: space-between;
}

.zijin_item_tab{
	margin-bottom: 12rpx;
}
</style>
